package com.insurance.web;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.insurance.bean.Agent;
import com.insurance.bean.Caze;
import com.insurance.service.CazeService;


public class CazeAction {
	@Resource CazeService cazeService;
	private String message;
	private List<Caze> cazes;
	private List<Caze> cazes0;
	private List<Caze> cazes1;
	private List<Caze> cazes2;
	private List<Caze> cazes3;
	private List<Caze> cazes4;
	private List<Caze> cazes5;
	private List<Caze> cazes6;
	private List<Caze> cazes7;
	private List<Caze> cazes8;
	private List<Caze> cazes9;
	private List<Caze> cazes10;
	private List<Caze> cazes11;
	private Caze caze;
	private Integer id;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Caze getCaze() {
		return caze;
	}
	public List<Caze> getCazes1() {
		return cazes1;
	}
	public void setCazes1(List<Caze> cazes1) {
		this.cazes1 = cazes1;
	}
	public List<Caze> getCazes0() {
		return cazes0;
	}
	public void setCazes0(List<Caze> cazes0) {
		this.cazes0 = cazes0;
	}
	public List<Caze> getCazes2() {
		return cazes2;
	}
	public void setCazes2(List<Caze> cazes2) {
		this.cazes2 = cazes2;
	}
	public List<Caze> getCazes3() {
		return cazes3;
	}
	public void setCazes3(List<Caze> cazes3) {
		this.cazes3 = cazes3;
	}
	public List<Caze> getCazes4() {
		return cazes4;
	}
	public void setCazes4(List<Caze> cazes4) {
		this.cazes4 = cazes4;
	}
	public List<Caze> getCazes5() {
		return cazes5;
	}
	public void setCazes5(List<Caze> cazes5) {
		this.cazes5 = cazes5;
	}
	public List<Caze> getCazes6() {
		return cazes6;
	}
	public void setCazes6(List<Caze> cazes6) {
		this.cazes6 = cazes6;
	}
	public List<Caze> getCazes7() {
		return cazes7;
	}
	public void setCazes7(List<Caze> cazes7) {
		this.cazes7 = cazes7;
	}
	public List<Caze> getCazes8() {
		return cazes8;
	}
	public void setCazes8(List<Caze> cazes8) {
		this.cazes8 = cazes8;
	}
	public List<Caze> getCazes9() {
		return cazes9;
	}
	public void setCazes9(List<Caze> cazes9) {
		this.cazes9 = cazes9;
	}
	public List<Caze> getCazes10() {
		return cazes10;
	}
	public void setCazes10(List<Caze> cazes10) {
		this.cazes10 = cazes10;
	}
	public List<Caze> getCazes11() {
		return cazes11;
	}
	public void setCazes11(List<Caze> cazes11) {
		this.cazes11 = cazes11;
	}
	public void setCaze(Caze caze) {
		this.caze = caze;
	}
	/**
	 * case home
	 */
	public String index(){
		this.cazes0 = cazeService.getCazesByType(0);
		this.cazes1 = cazeService.getCazesByType(1);
		this.cazes2 = cazeService.getCazesByType(2);
		this.cazes3 = cazeService.getCazesByType(3);
		this.cazes4 = cazeService.getCazesByType(4);
		this.cazes5 = cazeService.getCazesByType(5);
		this.cazes6 = cazeService.getCazesByType(6);
		this.cazes7 = cazeService.getCazesByType(7);
		this.cazes8 = cazeService.getCazesByType(8);
		this.cazes9 = cazeService.getCazesByType(9);
		this.cazes10 = cazeService.getCazesByType(10);
		this.cazes11 = cazeService.getCazesByType(11);
		return "index";
	}
	/**
	 * show all cases
	 */
	public String list(){
		this.cazes = cazeService.getCazes();
		return "list";
	}
	/**
	 * show all cases of specific agent
	 */
	public String alist(){
		Agent agent = (Agent)ServletActionContext.getRequest().getSession().getAttribute("agent");
		this.cazes = this.cazeService.getCazesByWriter(agent.getName());
		return "alist";
	}
	/**
	 * show a case by id
	 */
	public String show(){
		this.caze = this.cazeService.getCaze(this.id);
		return "show";
	}
	
	/**
	 * add UI
	 */
	public String addUI(){
		return "add";
	}
	
	/**
	 * add a case
	 */
	public String add(){
		Agent agent = (Agent)ServletActionContext.getRequest().getSession().getAttribute("agent");
		if(agent==null)
			return "fail";
		
		else{
			
		caze.setCazeTime(new Date()); 
		caze.setUserName(agent.getName());
		this.cazeService.save(this.caze);
		this.message="add a case success!";
		return "message";}
	}
	
	/**
	 * 
	 * modify UI
	 */
	public String modifyUI(){
		this.caze = this.cazeService.getCaze(this.id);
		return "modify";
	}
	
	/**
	 * 
	 * modify the case
	 */
	public String modify(){
		this.cazeService.update(caze);
		this.message="modify success";
		return "message";
		
	}
	
	/**
	 * 
	 * delete a caze by id
	 */
	public String del(){
		this.cazeService.delete(this.id);
		this.message="delete case success";
		return "message";
	}
	
	public List<Caze> getCazes() {
		return cazes;
	}

	public void setCazes(List<Caze> cazes) {
		this.cazes = cazes;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
}
